AVERAGEX

返回列中所有数字的平均值(算术平均值)

语法

AVERAGE ( <ColumnName> )
参数 属性 描述
表名 使用表达式每行计值的表
表达式 为表的每一行求值的表达式

返回值

#标量 一个货币或者小数类型的值

备注

示例

--  AVERAGEX is required when you need to iterate over
--  a table an average the result of a measure
DEFINE
    MEASURE Sales[Sales Amount] = SUMX ( Sales, Sales[Quantity] * Sales[Net Price] )
    MEASURE Sales[AVG Customer] = AVERAGEX ( Customer, [Sales Amount] )
EVALUATE
SUMMARIZECOLUMNS (
    'Customer'[Continent],
    "AVG Customer", [AVG Customer]
)

需要迭代一张表或者表变量

--  AVERAGEX is needed to iterate the content of a variable
DEFINE
    MEASURE Sales[Sales Amount] =
        SUMX ( Sales, Sales[Quantity] * Sales[Net Price] )
    MEASURE Sales[AVERAGE Monthly Sales] =
        VAR MonthlySales =
            ADDCOLUMNS (
                DISTINCT ( 'Date'[Calendar Year Month] ),
                "@MonthlySales", [Sales Amount]
            )
        VAR FilteredSales =
            FILTER ( MonthlySales, [@MonthlySales] > 10000 )
        VAR Result =
            -- Iterator required to aggregate the @MonthlySales column       
            AVERAGEX ( FilteredSales, [@MonthlySales] )
        RETURN
            Result
EVALUATE
SUMMARIZECOLUMNS (
    'Product'[Color],
    "AVERAGE Monthly Sales", [AVERAGE Monthly Sales]
)

忽略空值,但是会考虑0

--  AVERAGEX ignores blanks, it considers zeroes
EVALUATE
    VAR ValsWithBlank = { 1, 2, 3, BLANK () }
    VAR ValsWithZero  = { 1, 2, 3, 0        }
RETURN
    {
        ( "Average with BLANK", AVERAGEX ( ValsWithBlank, [Value] ) ),
        ( "Average with zero",  AVERAGEX ( ValsWithZero,  [Value] ) )
    }

相关函数

AVERAEA
AVERAGE